<template>
	<!-- 新版版头部 -->
	<view class="mp-header">
		<view class="locals" @click="toCitySelect">
			<view class="city">
				<image src="/static/images/dingwei.png" class="icomgs"></image>
				<text style="color: #fff;">{{city||'定位失败'}}</text>
			</view>
			<view class="addr">{{address}}</view>
		</view>
		<view class="serch-box tui-skeleton">
			<view class="serch-wrapper flex">
				<navigator url="/pages/columnGoods/goods_search/index"
					:class="(logoConfig || site_logo) ? 'input' : 'uninput'" hover-class="none" class="skeleton-rect">
					搜索商品
					<text class="iconfont icon-xiazai5"></text>
				</navigator>
			</view>
		</view>
	</view>
</template>
<script>
	let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
	import {
		configMap
	} from '@/utils';
	export default {
		name: 'head',
		props: {
			city: {
				type: String,
				default: ''
			},
			address: ''
		},
		computed: configMap({
			site_logo: ''
		}),
		data() {
			return {
				statusBarHeight: statusBarHeight,
				scrollHeight: 0,
				interval: 2500,
				marTop: 50,
				searchH: 0,
				logoConfig: "",
				hotWords: [],
				tabClick: 0, //导航栏被点击
				isLeft: 0, //导航栏下划线位置
				isWidth: 0, //每个导航栏占位
				mainWidth: 0,
				tabLeft: 0,
				swiperIndex: 0,
				childIndex: 0,
				childID: 0,
				tabTitle: [],
				fixedTop: 0,
				isTop: 0,
				navHeight: 38,
				indicatorDots: false,
				circular: true,
				autoplay: true,
				intervals: 3000,
				duration: 500,
				imgUrls: [], //图片轮播数据
				imageH: 0,
				swiperCur: 0,
				swiperType: 1,
				searchVal: '',
				bgColor: "",
				tabId: false,
				isCategory: false,
				swiperTop: 0,
				isFixed: true,
				localAddress: {}
			};
		},
		watch: {
			imageH(nVal, oVal) {
				this.imageH = nVal
			},
			city(nva, oVla) {
				if (!nva) {
					let localAddress = uni.getStorageSync("localAddress")
					if (localAddress) {
						this.city = localAddress.city;
						this.address = localAddress.address
					}
				}
			}
		},
		

		methods: {
			loadAddre() {
				var that = this
				// 获取设备宽度
				uni.getSystemInfo({
					success(e) {
						that.mainWidth = e.windowWidth
						that.isWidth = (e.windowWidth - 65) / 8
					}
				})
				// uni.getLocation({
				// 	type: 'gcj02',
				// 	geocode: true,
				// 	success: res => {
				// 		that.geocode(res.latitude, res.longitude)
				// 	},
				// 	fail: err => {
				// 		console.log('fail', err)
				// 	}
				// })
			
			},
			geocode(lat, lng) {
        console.log('headArrow')
				let that = this;
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/regeo',
					method: 'GET',
					data: {
						key: '662622b98a2c321b0f5e3bdca0a32155',
						location: lng.toFixed(6) + ',' + lat.toFixed(6)
					},
					success: res => {
						const {
							data
						} = res;
						that.city = data.regeocode.addressComponent.city;
						that.address = data.regeocode.formatted_address
						let localAddress = {
							city: data.regeocode.addressComponent.city,
							address: data.regeocode.formatted_address,
							"latitude": lat,
							"longitude": lng
						}
						uni.setStorageSync("localAddress", localAddress)
						uni.$emit("upShop", {})
					}
				})
			},
			handelCity(e) {
				console.log("hangdel", e)
			},
			toCitySelect() {
				uni.navigateTo({
					url: '/pages/citySelect/index'
				})
			},
			goDetail(url) {
				let urls = url.info[1].value
				this.$util.JumpPath(urls);
			},
			//替换安全域名
			setDomain: function(url) {
				url = url ? url.toString() : '';
				//本地调试打开,生产请注销
				if (url.indexOf("https://") > -1) return url;
				else return url.replace('http://', 'https://');
			},
			swiperChange(e) {
				let {
					current,
					source
				} = e.detail;
				if (source === 'autoplay' || source === 'touch') {
					this.swiperCur = e.detail.current;
					this.bgColor = this.imgUrls[e.detail.current]['img']
				}
			},
			textChange(e) {
				let {
					current,
					source
				} = e.detail;
				if (source === 'autoplay' || source === 'touch') {
					this.searchVal = this.hotWords[e.detail.current]['val']
				}
			},
			/**显示全部分类*/
			showCategory() {
				this.isCategory = true;
			},

		},
	}
</script>

<style lang="scss" scoped>
	.addr {
		font-size: 24rpx;
		margin-left: 20rpx;
		width: 70%;
		color: #fff;
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    word-break: break-all;
	}

	.city {
		display: flex;
		align-items: center;
	}

	.icomgs {
		width: 40rpx;
		height: 40rpx;
	}

	.locals {
		margin-top: 100rpx;
		margin-left: 30rpx;
		display: flex;
		align-items: center;
	}

	.margin-left-5 {
		margin-left: 10rpx;
	}

	.map-txt {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		word-break: break-all;
	}

	.page_count {
		position: relative;
		overflow: hidden;

		.bg-img {
			position: absolute;
			width: 100%;
			height: 100%;
			top: 0;
			/* #ifdef MP || APP-PLUS */
			z-index: -1;
			/* #endif */
			/* #ifdef H5 */
			z-index: 0;
			/* #endif */
			z-index: 0;
			filter: blur(0);
			overflow: hidden;

			img {
				width: 100%;
				height: 100%;
				filter: blur(30rpx);
				transform: scale(1.5);
			}
		}
	}

	.my-main {
		// transition: background-color .5s ease;
	}

	.swiperTxt {
		width: 300rpx;
		line-height: 64rpx;
		height: 64rpx;
		overflow: hidden;
	}

	.swiperTxt .text {
		width: 480rpx;
	}

	.swiperTxt .text .newsTitle {
		width: 300rpx;
		font-size: 24rpx;
		color: #ffffff;
	}

	.swiperTxt swiper {
		height: 100%;
	}

	.header {
		z-index: 99;
		position: fixed;
		left: 0;
		width: 100%;

		.btn {
			position: relative;
			margin-left: 30rpx;

			.iconfont {
				font-size: 45rpx;
			}
		}

		.iconnum {
			min-width: 14rpx;
			color: #E93323;
			background: #fff;
			border-radius: 15rpx;
			position: absolute;
			right: -10rpx;
			top: -10rpx;
			font-size: 10px;
			padding: 0 5px;
		}

		.serch-wrapper {
			align-items: center;
			padding: 20rpx 30rpx 20rpx 30rpx;

			.logo {
				width: 133rpx;
				margin-right: 20rpx;
			}

			image {
				width: 133rpx;
				height: 66rpx;
			}

			.box {
				flex: 1;
			}

			.input,
			.uninput {
				line-height: 64rpx;
				height: 64rpx;
				padding: 0 0 0 30rpx;
				background: #f5f5f5;
				color: #fff;
				border-radius: 30rpx;
				font-size: 28rpx;
				z-index: 2;
				position: relative;
				box-sizing: border-box;

				.iconfont {
					position: absolute;
					right: 20rpx;
					top: 0;
					color: #eeeeee;
				}
			}
		}
	}

	.mp-header {
		z-index: 99;
		position: relative !important;
		top: 0;
		/* 设置吸顶的位置 */
		left: 0;
		width: 100%;
			.box {
			flex: 1;
		}

		.serch-box {
			margin-top: 20rpx;
		}

		.serch-wrapper {
			display: flex;
			align-items: center;
			padding: 0 50rpx 20rpx 30rpx;
			height: 76rpx;

			.logo {
				width: 133rpx;
				margin-right: 20rpx;
				line-height: 0;
			}

			image {
				width: 118rpx;
				height: 42rpx;
			}

			.input,
			.uninput {
				display: flex;
				/* #ifdef MP */
				flex: 0;
				/* #endif */
				/* #ifdef APP-PLUS */
				flex: 1;
				/* #endif */
				flex: 1;
				align-items: center;
				height: 64rpx;
				line-height: 64rpx;
				padding: 0 50rpx 0 30rpx;
				background: #f7f7f7;
				border-radius: 100rpx;
				color: #999;
				font-size: 28rpx;
				position: relative;
				box-sizing: border-box;

				.iconfont {
					position: absolute;
					right: 20rpx;
					top: 0;
					color: #eeeeee;
				}
			}

			/* #ifdef MP */
			.uninput {
				max-width: 500rpx;
			}

			.input {
				max-width: 340rpx;
			}

			/* #endif */
		}
	}

	.tabNav {
		padding-top: 10rpx;
	}

	.navTabBox {
		color: rgba(255, 255, 255, 1);
		padding: 0 30rpx;
		z-index: 10;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		position: fixed;

		scroll-view {
			width: 100%;
			padding-right: 30rpx;
			height: 70rpx;
		}

		.click {
			color: white;
		}

		.longTab {
			.longItem {
				height: 50 upx;
				display: inline-block;
				line-height: 50 upx;
				text-align: center;
				font-size: 28rpx;
				color: #FFFFFF;
				max-width: 160rpx;
				margin-right: 30rpx;
				position: relative;

				&:last-child {
					margin-right: 0;
				}

				&.click {
					font-weight: bold;
					font-size: 30rpx;
					color: #FFFFFF;

					&::after {
						content: '';
						transition: .5s;
						width: 33rpx;
						height: 4rpx;
						background: #FFFFFF;
						position: absolute;
						bottom: -4rpx;
						left: 50%;
						margin-left: -16rpx;
					}
				}
			}
		}
	}

	.scrolled {
		z-index: 5000;
		position: fixed;
		min-height: 90rpx;
		left: 0;
		top: 0;
		width: 100%;
		background: #fff !important;
		transition: background-color .5s ease;

		.longItem,
		.click,
		.category text {
			color: #000000 !important;
		}

		.navTabBox,
		.mp-header,
		.header {
			// transition: background-color .5s ease;
			background: #ffffff;
		}

		.btn .iconfont {
			color: #333333 !important;
		}

		.iconnum {
			background: #333333 !important;
		}

		.underline {
			background: #000000 !important;
		}

		.click {
			&::after {
				background-color: #fff !important;
			}
		}
	}

	.swiperBg {
		z-index: 1;
		margin-top: 10rpx;
		padding-bottom: 30rpx;

		.colorBg {
			position: absolute;
			left: 0;
			top: 0;
			height: 130rpx;
			width: 100%;
		}

		.page_swiper {
			position: relative;
			width: 100%;
			height: auto;
			margin: 0 auto;
			border-radius: 10rpx;
			overflow-x: hidden;
			z-index: 8;
			padding: 0 10rpx;

			swiper-item {
				border-radius: 10rpx;
			}

			.swiper-item,
			image,
			.acea-row.row-between-wrapper {
				width: 100%;
				margin: 0 auto;
				border-radius: 10rpx;
			}

			swiper {
				width: 100%;
				display: block;
				height: auto;

				&.scalex {
					/deep/ .uni-swiper-slide-frame {
						transform: translate(0, 0) !important;
					}
				}
			}

			image {
				transform: scale(0.93);
				transition: all 0.6s ease;
			}

			swiper-item.active,
			swiper-item.scalex {
				image {
					transform: scale(1);
				}
			}

			/*用来包裹所有的小圆点  */
			.dots {
				width: 156rpx;
				height: 36rpx;
				display: flex;
				flex-direction: row;
				position: absolute;
				left: 320rpx;
				bottom: 0;
			}

			/*未选中时的小圆点样式 */
			.dot {
				width: 16rpx;
				height: 6rpx;
				border-radius: 6rpx;
				margin-right: 6rpx;
				background-color: rgba(255, 255, 255, .4);

				/*选中以后的小圆点样式  */
				&.active {
					width: 32rpx;
					height: 6rpx;
					background-color: rgba(255, 255, 255, .4);
				}
			}
		}
	}

	/deep/ .dot0 .uni-swiper-dots-horizontal {
		left: 10%;
	}

	/deep/ .dot1 .uni-swiper-dots-horizontal {
		left: 50%;
	}

	/deep/ .dot2 .uni-swiper-dots-horizontal {
		left: 90%;
	}
</style>